<template lang="pug">
  Upload(
    ref="upload"
    :before-upload="handleBeforeUpload"
    :on-success="handleUploadSuccess"
    :show-upload-list="false"
    :action="baseUrl + 'api/Employee/' + employeeId + '/PictureUpload'"
    :data="params"
    :max-size="10 * 1024"
    :on-exceeded-size="handleMaxSizeTen"
    :headers="headers"
  )
    Button(type="info" ghost :disabled="!isCanUpload") 点击上传压缩包
</template>

<script>
import Cookies from 'js-cookie'
import config from '@/config'
const baseUrl = process.env.NODE_ENV === 'development' ? config.baseUrl.dev : config.baseUrl.pro.replace('/api', '/')

export default {
  name: 'upLoadZip',

  data () {
    return {
      headers: {
        'Authorization': 'Bearer ' + Cookies.get('clientToken')
      },
      baseUrl: baseUrl
    }
  },

  props: ['employeeId', 'params', 'row', 'isCanUpload'],

  methods: {
    handleBeforeUpload () {
      this.$emit('before', this.row)
    },

    handleUploadSuccess (res) {
      this.$emit('uploadZip', res, this.row)
    },

    handleMaxSizeTen () {
      this.$Message.error({
        content: '您上传的文件太大，上传文件大小不能超过10M',
        duration: 10,
        closable: true
      })
    }
  },

  mounted () {
  }
}
</script>

<style scoped lang="scss" rel="stylesheet/scss">
</style>
